<template>
  <div>
    <eagle-tab-page-list
      url="/PlanEmergencyFileManage/GetPageData"
      :params="params"
      :filterParams="filterParams"
      :filterTab="filterTab"
      :activeFilter="activeFilter"
      @initActive="_initActive"
      @initList="_initList"
      ref="eagleTabPageList"
    >
      <div v-if="this.active === 0">
        <eagle-cell class="card" v-for="(item, index) in list" :key="index">
          <div>
            <div @click="goToDetail(item)">
              <eagle-row>
                <eagle-col span="24">
                  <h3>{{ item.FileName }}</h3>
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />文件类型：{{ item.PlanTypeName }}</eagle-col
                >
              </eagle-row>

              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                  />最近修改人：{{ item.EditChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />最近修改日期：{{ gettimeS(item.EditDate) }}
                </eagle-col>
              </eagle-row>
              <eagle-file-list
                :attachs="item.IssueMainAttach"
                :labelName="'签发版本:'"
              ></eagle-file-list>
            </div>
          </div>
        </eagle-cell>
      </div>
      <div v-if="this.active === 1">
        <eagle-cell class="card" v-for="(item, index) in list" :key="index">
          <eagle-tag v-if="item.Status === 10" class="info_tag" color="#1989fa"
            >现行
          </eagle-tag>
          <eagle-tag v-if="item.Status === 0" class="info_tag" type="warning"
            >未发行
          </eagle-tag>
          <eagle-tag v-if="item.Status === -1" class="info_tag" type="danger"
            >废止
          </eagle-tag>
          <div>
            <div @click="goToDetailList(item)">
              <eagle-row>
                <eagle-col span="24">
                  <h3>{{ item.FileName }}</h3>
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />文件类型：{{ item.PlanTypeName }}</eagle-col
                >
              </eagle-row>

              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                  />最近修改人：{{ item.EditChnName }}</eagle-col
                >
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />最近修改时间：{{ gettimeS(item.EditDate) }}</eagle-col
                >
              </eagle-row>
              <eagle-file-list
                :attachs="item.IssueMainAttach"
                :labelName="'签发版本:'"
                v-if="item.IssueMainAttach"
              ></eagle-file-list>
              <eagle-file-list
                :attachs="item.EditMainAttach"
                :labelName="'编辑版本:'"
                v-if="item.EditMainAttach"
              ></eagle-file-list>
              <eagle-divider />
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.Status != -1 && item.Status != 0"
                @click.stop="abo(item)"
                >废止
              </eagle-button>
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.Status == 0"
                @click.stop="del(item)"
                >删除
              </eagle-button>
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                @click.stop="history(item)"
                >修订历史
              </eagle-button>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-tab-page-list>
  </div>
</template>

<script>
import { getDate } from "@/utils/getDate.js";
import FileListReadOnly from "../../../components/Attach/FileListReadOnly.vue";
export default {
  components: { FileListReadOnly },
  data() {
    return {
      active: 0,
      list: [],
      params: [
        {
          title: "现行预案文件",
          dataType: "Publish",
          orgCode: -1,
        },
        {
          title: "预案文件管理",
          dataType: "List",
          orgCode: -1,
        },
      ],
      showTab: false,
      filterTab: false,
      filterParams: [
        {
          name: "Status",
          title: "状态",
          originTitle: "状态",
          dataType: "int",
          data: [
            { text: "不限", value: "" },
            { text: "未发行", value: "0" },
            { text: "现行", value: "10" },
            { text: "废止", value: "-1" },
          ],
        },
      ],
      activeFilter: [
        {
          active: 0,
          filter: false,
        },
      ],
    };
  },
  methods: {
    _initActive(active) {
      if (active === 1) {
        this.filterTab = true;
      }
      if (active === 0) {
        this.filterTab = false;
      }
      this.active = active;
    },
    _initList(list) {
      this.list = list;
    },
    _fileUploadCb(attachs) {
      this.form.Attach = attachs;
    },
    gettimeS(data) {
      return getDate(data);
    },
    goFile(attachCode) {
      this.$router.push("/Attach/AatachDetail?attCode=" + attachCode);
    },
    //删除
    del(item) {
      const _this = this;
      const id = item.ID;
      this.$dialog
        .confirm({
          title: "询问",
          message: "您确定删除该应急预案文件吗？",
        })
        .then(() => {
          _this.$axios
      	  .get("/PlanEmergencyFileManage/Delete",{params:{ id: item.ID }})
          .then((res) => {
            _this.$toast.success("删除成功！");
            _this.$refs.eagleTabPageList.getList();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    //审批历史
    history(item) {
      this.$router.push({
        path: "/PlanEmergencyFileManageLog",
        query: {
          code: item.SourceCode,
        },
      });
    },
    //废止
    abo(item) {
      const _this = this;
      this.$dialog
        .confirm({
          title: "询问",
          message: "您确定废止该应急预案文件吗？",
        })
        .then(() => {
          _this.$axios
      	  .get("/PlanEmergencyFileManage/Abolish",{params:{ code: item.FileManageCode }})
          .then((res) => {
            _this.$toast.success("操作成功！");
            _this.$refs.eagleTabPageList.getList();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    goToDetail(item) {
      this.$router.push({
        path: "/PlanEmergencyFileManageView",
        query: { id: item.ID, code: item.FileManageCode },
      });
    },
    goToDetailList(item) {
      this.$router.push({
        path: "/PlanEmergencyFileManageView",
        query: { id: item.ID, code: item.FileManageCode, isEdit: true },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.dep_sort {
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
</style>
